package antoine.ear.exo.intervalles;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Track;

import antoine.ear.exo.Exo;
import antoine.ear.generator.NoteGenerator;

public class FindInter2 extends Exo {

	public FindInter2(int tempo, int octave) {
		super(tempo, octave);
	}
	
	public String getPrintableResult() {
		return soluce;
	}

	public void generate() throws Exception {
		try {
			Sequence seq = new Sequence(Sequence.PPQ, 1);
			Track track = seq.createTrack();
			int note1 = NoteGenerator.generateNote(1);
			int note2 = NoteGenerator.generateNote(this.getOctave());
			
			indication = NoteGenerator.getNoteName(note1);
			soluce = NoteGenerator.getNoteName(note2); 
			
			track.add(createNoteOnEvent(note1, 0));
			track.add(createNoteOffEvent(note1, 1));
			track.add(createMetaMessOnEvent(note1, 0, ACTIVATENOTE));
			track.add(createMetaMessOnEvent(note1, 1, DESACTIVATENOTE));
			
			track.add(createNoteOnEvent(note2, 1));
			track.add(createNoteOffEvent(note2, 2));
			track.add(createMetaMessOnEvent(note2, 1, ACTIVATENOTE));
			track.add(createMetaMessOnEvent(note2, 2, DESACTIVATENOTE));
			
			track.add(createMetaMessOnEvent(0, 2, 11));
			
			soluce = "L'intervalle est "+indication+"-"+soluce;
					
			this.setSequence(seq);
			setTempo(tempo);
		} catch (InvalidMidiDataException e) {
			throw new Exception(e); 
		}
	}

	public String getIndication() {
		return "La basse est " + indication;
	}

}
